import {Injectable} from '@angular/core';
import * as API from "@api/index";
import {ToolsService} from "@shared/service/tools/tools.service";
import {HttpService} from "@core/http/http.service";
import {Observable} from "rxjs/Observable";
import {SNSResult, StudentScheduleCourseWrapVO} from "@interface/index";
// import {SNSResult} from "@interface/interface/interface.model";
// import {StudentScheduleCourseWrapVO} from "@interface/train/train.model";


@Injectable()
export class TrainService {

  constructor(
    public httpService: HttpService,
    public toolsService: ToolsService
  ) {
  }

  /**
   * @description 查询点评详情(教练)
   * @author ouyqx-691
   * @date 2017-12-27
   */
  getRemarkDetailForTeacher(params) {
    const url = API.GET_REMARK_DETAIL + "?" + this.toolsService.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @description 查询点评详情(教练)
   * @author ouyqx-691
   * @date 2017-12-27
   */
  getRemarkDetailForParent(params) {
    const url = API.TRAIN_SUBJECT_COMMENT + "?" + this.toolsService.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @description 更新点评
   * @author ouyqx-691
   * @date 2017-12-27
   */
  updateRemark(data) {
    const url = API.UPDATE_REMARK;
    return this.httpService.postUrlencode(url, data).map((res) => res.json());
  }

  /**
   * @description 新增点评
   * @author ouyqx-691
   * @date 2018-1-2
   */
  addRemark(data) {
    const url = API.ADD_REMARK;
    return this.httpService.postUrlencode(url, data).map((res) => res.json());
  }

  /**
   * @description 根据学员信息查询班级列表
   * @author ouyqx-691
   * @date 2017-12-30
   */
  getClassListForParent(params) {
    const url = API.GET_CLASS_LIST_BY_STUDENT_INFO + "?" + this.toolsService.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @description 根据老师信息查询班级列表
   * @author ouyqx-691
   * @date 2017-12-30
   */
  getClassListForTeacher(params) {
    const url = API.GET_CLASS_LIST_BY_TEACHER_INFO + "?" + this.toolsService.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @description 根据班级信息查询学员列表（教练）
   * @author ouyqx-691
   * @date 2017-12-31
   */
  getStudentListForTeacher(params) {
    const url = API.GET_STUDENGT_LIST_BY_CLASS_INFO + "?" + this.toolsService.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @description 根据班级信息查询学员列表（教练）
   * @author ouyqx-691
   * @date 2017-12-31
   */
  getLessonListForTeacher(params) {
    const url = API.GET_LESSON_LIST_BY_STUDENT_INFO + "?" + this.toolsService.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  getCourseCount(startTime: Date, endTime: Date, page: number, orgUserId: string): Observable<any> {   // 获取培训统计
    const start = this.dateTostr(startTime);
    const end = this.dateTostr(endTime);
    const url = API.TRAINCOUNT_URL + `?rows=10&page=${page}&beginTime=${start}&endTime=${end}&orgUserId=${orgUserId}`;
    return this.httpService.get(url).map(res => res.json());
  }

  getfindSignCount(startTime, endTime, orgUserId: string) {   // 课程考勤统计比例
    const start = this.dateTostr(startTime);
    const end = this.dateTostr(endTime);
    const url = API.FINDSIGNCOUNT_URL + `?beginTime=${start}&endTime=${end}&orgUserId=${orgUserId}`;
    return this.httpService.get(url).map(res => res.json());
  }

  getCourseList(params) {
    const url = API.GET_LIST_BY_COURSE + '?' + this.toolsService.param(params);
    return this.httpService.get(url).map(res => res.json());
  }

  getRollCallList(param): Observable<SNSResult<StudentScheduleCourseWrapVO>> {
    const url = API.ROLL_CALL_LIST + '?' + this.toolsService.param(param);
    return this.httpService.getUrlencode(url).map(res => res.json());
  }

  dateTostr(time: Date) {
    const string = `${time.getFullYear()}-${(time.getMonth() + 1) > 9 ? time.getMonth() +
      1 : '0' + (time.getMonth() + 1)}-${time.getDate() > 9 ? time.getDate() : '0' + time.getDate()}`;
    return string;
  }

  doAttendance(param) {
    const url = API.ROLL_CALL_DOATTENDANCE;
    return this.httpService.postUrlencode(url, param).map(res => res.json());
  }

  /**
   * @description 上传文件
   * @author ouyqx-691
   * @date 2017-12-31
   */
  upLoadFile(file) {
    const url = API.UPLOAD_IMAGE_COMPRESS;
    return this.httpService.uploadImage(url, file).map((res) => res.json());
  }

  /**
   * @description 查询孩子列表
   * @author ouyqx-691
   * @date 2017-12-31
   */
  getStudentListForParent() {
    const url = API.GET_CHILD_LIST;
    return this.httpService.get(url).map(res => res.json());
  }

  /**
   * @description 查询课时列表（家长）
   * @author ouyqx-691
   * @date 2017-12-31
   */
  getLessonListForParent(params) {
    const url = API.LIST_TRAIN_SUBJECT_COMMENT_BY_PAGE + "?" + this.toolsService.param(params);
    return this.httpService.get(url).map((res) => res.json());
  }

  /**
   * @description 删除点评（家长）
   * @author ouyqx-691
   * @date 2017-12-31
   */
  deleteRemark(param) {
    const url = API.DELETE_COMMENT;
    return this.httpService.postUrlencode(url, param).map((res) => res.json());
  }

  /**
   * @description 删除点评（家长）
   * @author ouyqx-691
   * @date 2017-1-5
   */
  updateRemarkReadState(params) {
    const url = API.UPDATE_COMMENT_READ_STATUS;
    return this.httpService.postUrlencode(url, params).map((res) => res.json());
  }

  /**
   * @author guoqs1331
   * @time 2018/3/16
   * @description 获取战术板信息
   */
  getTacticInfo(param){
    const url = API.TRAIN_TACTIC_INFO + "?" + this.toolsService.param(param);
    return this.httpService.get(url).map((res) => res.json());
  }
}


